package cn.com.zero.front.auth.controller;

import cn.com.zero.base.constant.ZeroRegexPatternConstants;
import cn.com.zero.common.auth.util.AuthUtil;
import cn.com.zero.front.auth.service.IUserService;
import cn.com.zero.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Pattern;

/**
 * @author liuxh
 * @version 1.0.0
 * @Description 用户注销
 * @createTime 2023/4/7 9:48
 */
@Validated
@RestController
@Api(tags = "用户注销接口")
@RequestMapping("/front/auth/cancellation")
public class UserCancellationController extends BaseController {

    private IUserService userService;

    @ApiOperation(value = "注销帐号申请")
    @ApiImplicitParam(paramType = "query", name = "phone", value = "紧急联系电话")
    @PostMapping("/apply")
    public void apply(@Pattern(regexp = ZeroRegexPatternConstants.MOBILE_EX) @RequestParam(value = "phone", required = false) String phone) {
        String userId = AuthUtil.getUserIdFromRequest();
        userService.applyCancellation(phone, userId);
    }


    @Autowired
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }
}
